/**
 * @file GetNewSubscriptionProtocolMessage.cs
 * @author Zane Mayo
 * @date 20/5/2009
 */

using System;
using System.Collections.Generic;

namespace MxitAPI {
	
	
	public class RawSubscription {
		public string ContactAddress;
		public string NickName;
		public ContactType ContactType;
		public int HiddenLoginName;
		public string InviteMessage;
		public string MultiMxCreator;
		
		public RawSubscription(){
		}
		
		public override string ToString ()
		{
			return string.Format("ContactAddress [{0}] | NickName [{1}] | ContactType [{2}] | HiddenLoginName [{3}] | InviteMessage [{4}] | MultiMxCreator [{5}] ", 
			                     ContactAddress, NickName, ContactType, HiddenLoginName, InviteMessage, MultiMxCreator );
		}

	}
	
	public class GetNewSubscriptionProtocolMessage : ProtocolMessage {
		
		private static log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType );
		
		public List<RawSubscription> RawSubscriptions { get; set; }
	
		
		public GetNewSubscriptionProtocolMessage() : base ( ProtocolMessageType.GetNewSubscription ) {
			RawSubscriptions = new List<RawSubscription>();
			
			log.Debug( "New GetNewSubscriptionProtocolMessage created" );
		}
	
		public override void SetResponse( string[][] response ) {
			log.Debug( "Response to set GetNewSubscriptionProtocolMessage to: " + response.ToString() );
			for ( int i = 2 ; i < response.Length ; ++i ) {
				// Check that all the fields for the the subscription details are there
				if ( response[i].Length < 6 )
					continue;
				RawSubscription rawSubscription = new RawSubscription();
				rawSubscription.ContactAddress = response[i][0];
				rawSubscription.NickName = response[i][1];
				rawSubscription.ContactType = (ContactType) Int32.Parse( response[i][2] );
				rawSubscription.HiddenLoginName = Int32.Parse( response[i][3] );
				rawSubscription.InviteMessage = response[i][4];
				rawSubscription.MultiMxCreator = response[i][5];
				RawSubscriptions.Add( rawSubscription );
			}
		}
		
		
	}
}
